package libra.init;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;


//标注配置类
@Configuration
//开启web配置
@EnableWebMvc
//开启事务配置
@EnableTransactionManagement
//指定包扫描
@ComponentScan("libra")
//读取properties文件
//@PropertySource(value={"classpath:db.properties"},encoding="UTF-8")

// 启用NacosConfig的配置管理服务
// 如果是nacos集群，可配置多个IP地址，使用','号隔开
//@EnableNacosConfig(globalProperties = @NacosProperties(serverAddr = "127.0.0.1:8848"))
@EnableNacosConfig(globalProperties = @NacosProperties(serverAddr = "127.0.0.1:8850,127.0.0.1:8860,127.0.0.1:8870"))
// 从NacosConfig加载指定dataId的配置文件。
// 'autoRefreshed'为动态刷新配置文件，默认为false(关闭)。注意!：该自动刷新针对的是'配置文件源'
@NacosPropertySource(dataId = Config.dataId, autoRefreshed = true)
public class Config implements WebMvcConfigurer {
	/** NacosConfig中对应的配置文件的dataId */
	public static final String dataId = "MvcConfig.json";
	
	//静态资源访问
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}
}
